<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:c="http://java.sun.com/jsp/jstl/core"
                template="./../templates/StakeholderPortalTemplate.xhtml">

    <ui:define name="content"> 
        <h:form id="formMain">
            <h1>View point redemptions in a specified period of time</h1>         
            <p:fieldset>
                <h:outputText value="Specify the period of time : " />
                <h:panelGrid id="display" columns="2" cellpadding="5">  
                    <h:outputText value="From : " />  
                    <p:calendar value="#{stakeholderULPManagerBean.inputDateFrom}" />   
                    <h:outputText value="Until : " />  
                    <p:calendar value="#{stakeholderULPManagerBean.inputDateUntil}" />
                    <p:commandButton value="View" actionListener="#{stakeholderULPManagerBean.retrieveRedemptionInPeriodList}" />
                    <p:commandButton value="View All Redemptions" actionListener="#{stakeholderULPManagerBean.retrieveAllRedemptionList}" />
                </h:panelGrid>         
            </p:fieldset>
            <br/>
            <br/>
            <p:panel rendered="#{stakeholderULPManagerBean.displayRedemptions}">
                <p:accordionPanel autoHeight="false" >
                    <p:tab title="View Redemptions (Double click to select) ">
                        <p:dataTable var="redemption" value="#{stakeholderULPManagerBean.redemptionInPeriodList}" paginator="true" 
                                     rows="10" emptyMessage="No redemption found" selection="#{stakeholderULPManagerBean.selectedRedemption}" 
                                     selectionMode="single" rowSelectListener="#{stakeholderULPManagerBean.onRowSelectNavigateViewRedemption}"
                                     dblClickSelect="true">

                            <p:column sortBy="#{redemption.id}" filterBy="#{redemption.id}">
                                <f:facet name="header">
                                    <h:outputText value="ID" />
                                </f:facet>
                                <h:outputText value="#{redemption.id}" />
                            </p:column>

                            <p:column sortBy="#{redemption.redemptionList.name}" filterBy="#{redemption.redemptionList.name}">
                                <f:facet name="header">
                                    <h:outputText value="Item name" />
                                </f:facet>
                                <h:outputText value="#{redemption.redemptionList.name}" />
                            </p:column>

                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Image" />
                                </f:facet>
                                <p:graphicImage id="imageDisplay" value="/images/upload/media/#{redemption.redemptionList.imageURL}"
                                                height="50" width="70"/> 
                            </p:column>

                            <p:column sortBy="#{redemption.referenceNumber}" filterBy="#{redemption.referenceNumber}">
                                <f:facet name="header">
                                    <h:outputText value="Reference Number" />
                                </f:facet>
                                <h:outputText value="#{redemption.referenceNumber}" />
                            </p:column>

                            <p:column sortBy="#{redemption.dateUsed}" filterBy="#{redemption.dateUsed}">
                                <f:facet name="header">
                                    <h:outputText value="Date Used" />
                                </f:facet>
                                <h:outputText value="#{redemption.dateUsed}">
                                    <f:convertDateTime dateStyle="full" timeZone="EST" type="date" />
                                </h:outputText>
                            </p:column>

                            <p:column sortBy="#{redemption.branch.name}" filterBy="#{redemption.branch.name}">
                                <f:facet name="header">
                                    <h:outputText value="Used at branch" />
                                </f:facet>
                                <h:outputText value="#{redemption.branch.name}" />
                            </p:column>

                            <p:column sortBy="#{redemption.redemptionList.costOfItem}" filterBy="#{redemption.redemptionList.costOfItem}">
                                <f:facet name="header">
                                    <h:outputText value="Cost of item" />
                                </f:facet>
                                <h:outputText value="#{redemption.redemptionList.costOfItem} SGD" />
                            </p:column>

                        </p:dataTable>
                    </p:tab>
                </p:accordionPanel> 
            </p:panel>
        </h:form>
    </ui:define>
</ui:composition>